import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from python_ai.common.xcommon import sep
pd.set_option('display.max_rows', None, 'display.max_columns', None, 'display.max_colwidth', 1000, 'display.expand_frame_repr', False)
plt.rcParams['font.sans-serif'] = ['Simhei']
plt.rcParams['axes.unicode_minus'] = False

pd.set_option('display.max_columns', None)

sep('data')
dict1 = {'x1': [16.9, 38.5, 39.5, 80.8, 82, 34.6, 116.1]}
df = pd.DataFrame(dict1)
print(df)

sep('cluster agg')
from sklearn.cluster import AgglomerativeClustering

model = AgglomerativeClustering(n_clusters=3)
model.fit(df)
print(model.labels_)

sep('dist')
import scipy.cluster.hierarchy as sch

dist = sch.distance.pdist(df[['x1']], 'euclidean')
print(dist)
print(len(dist))

model = sch.linkage(dist, 'average')

pic = sch.dendrogram(model, labels=list('ABCDEFG'))

plt.show()
